package org.huawei260.TiKu.ODsuanfa;

import java.util.Arrays;
import java.util.Scanner;
public class E_2024E_4000__位运算分苹果 {

//	public class Main {
		public static void main(String[] args) {
			Scanner sc = new Scanner(System.in);

			int n = sc.nextInt();
			int[] arr = new int[n];
			for (int i = 0; i < n; i++) {
				arr[i] = sc.nextInt();
			}

			System.out.println(getResult(n, arr));
		}

		public static int getResult(int n, int[] arr) {
			Arrays.sort(arr);

			int min = arr[0];
			int fault = min, correct = min;

			for (int i = 1; i < arr.length; i++) {
				int w = arr[i];
				fault ^= w;
				correct += w;
			}

			if (fault == 0) {
				return correct - min;
			} else {
				return -1;
			}
		}
	}